/**
 * 工作管理 - 人员管理API
 * 
 * @author Wu.Liang
 * @since 2025-01-30
 */

import api from '../request'
import type { ApiResponse } from '@/types'

// 员工查询参数
export interface StaffQueryParams {
  pageNum?: number
  pageSize?: number
  keyword?: string
  status?: number | null
  propertyCompanyIds?: string
}

// 员工信息
export interface StaffVO {
  id: number
  userId: number
  realName: string
  employeeNo?: string
  phone?: string
  email?: string
  avatar?: string
  gender?: number
  status: number
  statusText?: string
  department?: string
  position?: string
  joinDate?: string
  propertyCompanyId: number
  propertyCompanyName: string
  communityId?: number
  communityName?: string
  createTime: string
  updateTime: string
}

// 分页结果
export interface StaffPageResult {
  records: StaffVO[]
  total: number
  size: number
  current: number
  pages: number
}

/**
 * 工作管理 - 人员管理API
 */
export const workStaffApi = {
  /**
   * 分页查询员工列表
   */
  getStaffList: (params: StaffQueryParams) => {
    return api.get<ApiResponse<StaffPageResult>>('/api/work/staff/list', { params })
  },

  /**
   * 根据ID查询员工详情
   */
  getStaffById: (staffId: number) => {
    return api.get<ApiResponse<StaffVO>>(`/api/work/staff/${staffId}`)
  },

  /**
   * 添加员工
   */
  addStaff: (data: any) => {
    return api.post<ApiResponse<number>>('/api/work/staff', data)
  },

  /**
   * 更新员工信息
   */
  updateStaff: (staffId: number, data: any) => {
    return api.put<ApiResponse<null>>(`/api/work/staff/${staffId}`, data)
  },

  /**
   * 删除员工
   */
  deleteStaff: (staffId: number) => {
    return api.delete<ApiResponse<null>>(`/api/work/staff/${staffId}`)
  }
}

export default workStaffApi
